<template>
  <div>
    <el-dialog title="留言" :visible.sync="leaveWordVisible" center @close='leaveWordClose' class="leaveWordDialog">
      <span class='leaveWord-label'>请输入你的留言</span>
      <el-input type="textarea" v-model="leaveWordText"></el-input>
      <span slot="footer">
        <el-button type="warning" size="small" @click="leaveWordClose">取消</el-button>
        <el-button @click='submitLeaveWord' type="primary" size="small" v-no-more-click:3000 :loading="leaveWordLoading">确定</el-button>
      </span>
    </el-dialog>

    <!-- 信息提示框 -->
    <promptMessage ref='promptMessage' />
  </div>
</template>

<script>
import promptMessage from '~/components/promptMessage'
import {sendPrivateLetter} from '~/util/index'
export default {
  components: {
    promptMessage,
  },
  data () {
    return {
      leaveWordVisible: false,
      leaveWordLoading: false,
      leaveWordText: '',
      leaveWordId: null,
      rowData: {},
      leaveWordRole: ''
    }
  },
  methods: {
    showLeaveWord(data, role) {
      this.leaveWordVisible = true
      this.rowData = data
      this.leaveWordRole = role
    },
    quit(data){
      this.$router.push({
        path: '/user/news/communication',
        query:{
          data:JSON.stringify(data)//对象转为字符串
        }
      });
    },
    submitLeaveWord () {
      let that = this;
      let params = {
          news: that.leaveWordText,
          receive_uid: that.rowData.process_id,
          finals_id:that.rowData.id
      }
      that.$axios.post('api/news/add_private_letter', params).then(res => {
        if (res.data.code == 200) {
          // that.$message({
          //   type: 'success',
          //   message:"发送留言信息成功！"
          // })
          // that.leaveWordVisible = false
          // that.leaveWordText = ''
          // setTimeout(() => {
          //   that.quit(res.data.data)
          // }, 1000)
          that.$confirm('发送留言信息成功，要跳转到详情页面吗', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消'
          }).then(() => {
            that.leaveWordVisible = false
            that.leaveWordText = ''
            setTimeout(() => {
              that.quit(res.data.data)
            }, 1000)
          }).catch(() => {
            that.leaveWordVisible = false
            that.leaveWordText = ''
            // that.$message({
            //   type: 'info',
            //   message: '已取消跳转'
            // });  
          });
        }
      })
    //   let params = {
    //     message: this.leaveWordText,
    //     id: this.rowData.order.id
    //   }
    //   let url = ''
    //   this.leaveWordRole == 'process' ? url = `api/consumer/${params.id}/process/message` : url = `api/consumer/${params.id}/message`
    //   this.$axios.post(url, params)
    //   .then( ({data}) => {
    //     if (data.code == 200) {
    //       this.leaveWordVisible = false
    //       if (this.leaveWordRole == 'process') {
    //         let pData = {
    //           userName: this.$store.state.user.name,
    //           email: this.rowData.order.process.email_work,
    //           phone: this.rowData.order.process.phone,
    //           number: this.rowData.order.process.email_work.split("@")[0].split("followup")[1]
    //         }
    //         this.$refs['promptMessage'].showDialog('processLeaveWord',pData)
    //       }

    //       sendPrivateLetter(this, this.rowData.order.id, this.leaveWordText, this.rowData.order.process.id, 'final')
    //     }
    //   })
    },
    leaveWordClose () {
      this.leaveWordText = ''
      this.leaveWordVisible = false
    }
  }
}
</script>

<style lang='less'>
.leaveWordDialog {
  .el-dialog {
    width: 35%;
  }
  .leaveWord-label {
    display: block;
    margin-bottom: 10px;
  }
  .el-textarea {
    display: block;
    margin-bottom: 20px;
  }
}
</style>
